import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/theme-chalk/dark/css-vars.css'
import {createRouter,createWebHashHistory} from 'vue-router';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

import App from './App.vue'
import './styles/main.css'

import LoginPopout from './components/LoginPopout.vue'
import MainPopout from './components/MainPopout.vue'
import UserManager from './components/SystemManager/UserManager.vue'
import LogManager from './components/SystemManager/LogManager.vue'
import RoleManager from './components/SystemManager/RoleManager.vue'
import SerialnumManager from './components/SystemManager/SerialnumManager.vue'

const router = createRouter({
    history: createWebHashHistory(),
    routes:[
        { path: '/', component:LoginPopout},
        { path: '/main', component: MainPopout},
        { path: '/sys/user', component: UserManager},
        { path: '/sys/log', component: LogManager},
        { path: '/sys/role', component: RoleManager},
        { path: '/sys/serialnum', component:SerialnumManager }
    ]
})

const app = createApp(App)
app.config.productionTip = true
app.use(ElementPlus, {locale: zhCn})
    .use(router)
    .mount('#app')

window.cefQueryRequset = function(module, action, data, fn) {
    if(window.cefQuery!=undefined){
        return window.cefQuery({
            request: JSON.stringify({ "module": module, "action":action, "data": data }),
            persistent: false,
            onSuccess: function (response) {
                console.log("【"+module+"】 "+action+" success")
                if (response == null) {
                    if(typeof(fn)==="function") fn(true, [])
                }
                else {
                    if(typeof(fn)==="function" && response != undefined) fn(true, JSON.parse(response))
                }
            },
            onFailure: function (code, msg) { 
                console.log("【"+module+"】 "+action+" fail:",msg)
                fn(false, msg)
            }
        });
    }else{
        fn(true)
    }
};